package com.example.news.controller;

import com.example.news.pojo.form.*;
import com.example.news.pojo.vo.LoginVo;
import com.example.news.service.AuthService;
import com.example.news.utils.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/auth")
@Tag(name = "1.认证模块")
public class AuthController {

    @Autowired
    private AuthService authService;

    @GetMapping("/registerCaptcha/{email}")
    @Operation(summary = "注册验证码")
    public Result<String> getRegisterCaptcha(@PathVariable String email) {
        return authService.getRegisterCaptcha(email);
    }

    @PostMapping("/register")
    @Operation(summary = "用户注册")
    public Result<String> userRegister(@RequestBody RegisterForm registerForm) {
        return authService.userRegister(registerForm);
    }

    @GetMapping("/loginCaptcha/{email}")
    @Operation(summary = "登录验证码")
    public Result<String> getLoginCaptcha(@PathVariable String email) {
        return authService.getLoginCaptcha(email);
    }

    @PostMapping("/login")
    @Operation(summary = "用户登录")
    public Result<LoginVo> userLogin(@RequestBody LoginForm loginForm) {
        return authService.userLogin(loginForm);
    }

    @PostMapping("/loginByEmail")
    @Operation(summary = "用户邮箱登录")
    public Result<LoginVo> userLoginByEmail(@RequestBody EmailLoginForm emailLoginForm) {
        return authService.userLoginByEmail(emailLoginForm);
    }

    @PostMapping("/changePwd")
    @Operation(summary = "用户修改密码")
    public Result<String> changePwd(@RequestBody ChangePwdForm changePwdForm) {
        return authService.changeUserPassword(changePwdForm);
    }

    @PostMapping("/changePwdCaptcha/{email}")
    @Operation(summary = "密码修改邮箱验证码")
    public Result<String> getChangePwdCaptcha(@PathVariable String email) {
        return authService.getChangePwdCaptcha(email);
    }

    @PostMapping("/changePwdByEmail")
    @Operation(summary = "邮箱修改密码")
    public Result<String> userLoginByEmail(@RequestBody ChangePwdByEmailForm changePwdByEmailForm) {
        return authService.changeUserPwdByEmail(changePwdByEmailForm);
    }

}
